#include <iostream>
#include <cmath>
using namespace std;
long long get_coin(int day);
int main(){
	long long day , n , m, ans;
	freopen("coin.in", "r", stdin);
	freopen("coin.out", "w", stdout);
	while (cin >> day){
		if (day == 0 ) {
			return 0;
		}
		// long long idx = sqrt(2 * day);		
		// while((day - idx * (idx + 1) / 2) >= 0){
		//	idx++;
		// }		
		// n = idx - 1;
		// m = day - ((n + 1) * n) / 2;
		// ans = n * (n + 1) * (2 * n + 1) / 6 + (n + 1) * m;
		ans = get_coin(day);
		cout << ans << endl;
	}
	return 0;
}

long long get_coin(int day) {
	long long n = sqrt(2 * day);		
	while((day - n * (n + 1) / 2) >= 0){
		n++;
	}		
	n--;
	long long m = day - ((n + 1) * n) / 2;
	long long ans = n * (n + 1) * (2 * n + 1) / 6 + (n + 1) * m;
	return ans;
}
